$(function(){
    var openid = getQueryStr("openId");
    var code;
    var tel;
    
    /*用户点击获取验证码*/
    $(".get_btn").on("click",function(){
        var re = /^1\d{10}$/;
        var tel_click = $("input[type='tel']").val();
        tel = tel_click;
        if(re.test(tel)){
            $.ajax({
                type: "post",
                url: "http://www.pdhz-dddc.cn/dingding-web/regActiveAction!getValidateCode.action",
                dataType: "jsonp",
                async: false,
                jsonp: "callback",
                jsonpCallback: "success_jsonp",
                data: {
                    tellphone: tel
                },
                success: function(data){
                    if(data.responseBody == "error"){
                        alert("获取验证码失败");
                    }
                }
            });
            
          //获取验证码之后用户在一分钟之内不能再次点击获取，并实现一分钟倒计时，之后才能继续获取 
            var count = 60;
            var countdown = setInterval(CountDown, 1000);
            function CountDown() {
                $(".get_btn").attr("disabled", true);
                $(".get_btn").text(count + "s");
                if (count == 0) {
                    $(".get_btn").text("获取").removeAttr("disabled");
                    clearInterval(countdown);
                }
                count--;
            }
            
        }
        else{
            swal({
                title: "请输入正确的手机号码",
                type: "warning",
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
            });
        }
    });
        
    /*用户点击Go前往对应的活动主页*/
    $(".go_btn").on("click",function(){
        var code_get = $(".yzm").val();
        var tel_click_go = $("input[type='tel']").val();
        tel = tel_click_go;
        code = code_get;
        $.ajax({
            type: "post",
            url: "http://www.pdhz-dddc.cn/dingding-web/regActiveAction!finishReg.action",
            dataType: "jsonp",
            async: false,
            jsonp: "callback",
            jsonpCallback: "success_jsonp",
            data: {
                tellphone: tel,
                code: code,
                openId: openid
            },
            success: function(data){
                console.log(data);
                if(data.responseBody == "phoneNull"){
                    swal({
                        title: "手机号码为空",
                        type: "warning",
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                    });
                }
                if(data.responseBody == "codeNull"){
                    swal({
                        title: "验证码为空",
                        type: "warning",
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                    });
                }
                if(data.responseBody == "codeError"){
                    swal({
                        title: "验证码错误",
                        type: "warning",
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                    });
                }
                if(data.responseBody == "alreadyReg"){
                    swal({
                        title: "手机号码已经注册",
                        type: "warning",
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                    });
                }
                if(data.responseBody == "beijingResult"){
                    window.location.href = "bjresult.html";
                }
                if(data.responseBody == "tangshanResult"){
                    window.location.href = "tsresult.html";
                }
                if(data.responseBody == "otherResult"){
                    window.location.href = "http://121.40.105.132:8085/appdown/";
                }
            }
        });
    });
    
});